<?php
namespace app\zhongcan\validate;

use think\Validate;

class NewsValidate extends Validate
{
    //定义验证规则
    protected $rule = [
        'title' => 'require|max:30',
        'image' => 'require',
        'look_num' => 'require',
        'author' => 'require',
        'abstract' => 'require',
        'content' => 'require',
        //'create_time' => 'require',
        //'switch' => 'require|in:0,1'
    ];

    //定义验证失败时的提示信息
    protected $message = [
        'title.require' => '标题不能为空',
        'image.require' => '封面不能为空',
        'title.max' => '标题最多不能超过30个字符',
        'look_num.require' => '浏览量不能为空',
        'look_num.integer' => '浏览量应为整数',
        'author.require' => '作者不能为空',
        'author.max:10' => '作者最多不能超过10个字符',
        'abstract.require' => '摘要不能为空',
        'content.require' => '内容不能为空',

        //'create_time.require' => '创建时间不能为空',
        //'switch.integer' => '开关必须是整数',
    ];

    //验证场景
    protected  $scene = [
        'add' => ['image','title','abstract','content','author'],
        'edit' => ['image','title','abstract','content','author'],
    ];

}